var Promise = require('bluebird');
var User = require('mongoose').model('User');

module.exports = {
  createUser: function (user) {
    var defer = Promise.defer();
    User.findOne({username: user.username}, function (err, users) {
      if (err) {
        return defer.resolve(err)
      }
      if (users) {
        return defer.resolve({status: false})
      }

      User.create(user, function (err, user) {
        return err ? defer.resolve(err) : defer.resolve(user)
      })
    });
    return defer.promise;
  }
};